package com.zbc.demo.model.response;

import com.zbc.demo.exception.BaseException;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 响应体
 *
 * @author 万恶的沫白
 * @date 2021/8/13
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Body<T> {
    /**
     * 响应码，默认正常返回为 0
     */
    private int code = 0;
    /**
     * 响应消息，默认正常返回为"ok"
     */
    private String message = "ok";
    /**
     * 响应正文
     */
    private T content;

    public Body(T content) {
        if (content instanceof BaseException) {
            BaseException baseException = (BaseException) content;
            this.message = baseException.getMessage();
            this.code = baseException.getCode();
            this.content = null;
        } else {
            this.content = content;
        }
    }

}
